﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Common.AspNetCore.Structs
{
    public class ModelConfig
    {
        private readonly List<ModelFieldConfigBase> fields = null;

        public ModelConfig()
        {
            fields = new List<ModelFieldConfigBase>(); 
        }

        public string Name { get; set; }

        public string EntityName { get; set; }

        public string ModuleCode { get; set; }

        public string ModelIdApi { get; set; }

        public string ModelApi { get; set; }

        public string ModelOrderApi { get; set; }

        public string ModelOrderPageApi { get; set; }

        public List<ModelFieldConfigBase> Fields
        {
            get { return fields; }
        }

        public ModelFieldConfigBase GetFieldConfig(string name)
        {
            return fields.FirstOrDefault(t => string.Compare(t.Name, name, true) == 0);
        }

        public void AddFieldModelConfig(ModelFieldConfigBase field)
        {
            if (string.IsNullOrEmpty(field.Name))
            {
                return;
            }

            var f = fields.FirstOrDefault(t => string.Compare(t.Name, field.Name, true) == 0);
            if (f != null)
            {
                fields.Remove(f);
            }

            fields.Add(field);
        }
    }
}
